package com.kitty.game.fight.artifact.passive;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.fight.SkillConst;
import com.kitty.game.fight.util.FightMessageUtil;
import com.kitty.game.fight.util.FightRateUtil;
import com.kitty.game.utils.Const;
import com.kitty.game.utils.StatusConst;
import com.kitty.mina.message.Message;
import com.kitty.mina.message.MessagePusher;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 天眼
 * 类似火眼金睛道具，只限pvp
 */
public class SkyEyeArtifactEffect extends ArtifactEffect {

    @Override
    public short getEffectId() {
        return 0;
    }

    @Override
    public ArtifactType getType() {
        return ArtifactType.SKY_EYE;
    }

    @Override
    public Object trigger(Fight fight, FightObject effector, Object... params) {
        if (!effector.isPlayer()) {
            return false;
        }
        if (SpringUtils.getArtifactService().getSpecialSkillId(effector) != SkillConst.SKILL_TIAN_YAN) {
            return Boolean.FALSE;
        }
        int lastRound = effector.getStatusScore(StatusConst.STATUS_EYE);
        if (lastRound > 0 && lastRound < fight.getRound()) {
            MessagePusher.pushMessage(effector.getRole(),
                    SpringUtils.getFightMessageService().clearEyeInfo());
        }
        if (!checkBaseCondition(fight, effector)) {
            return false;
        }

        List<FightObject> enemies = fight.getTargetSide(effector.getId());
        List<FightObject> showList = new ArrayList<>(enemies);
        Collections.shuffle(showList);
        // 随机显示对方最多XX个
        if (showList.size() > 3) {
            showList = showList.subList(0, 3);
        }
        Message hpMsg = SpringUtils.getFightMessageService().eyeInfo(showList);
        FightMessageUtil.sendFightPackage(fight, hpMsg,effector.isASide());

        // 持续五个回合
        effector.setStatusScore(StatusConst.STATUS_EYE, fight.getRound() + 5);

        return true;
    }

    @Override
    protected boolean checkBaseCondition(Fight fight, FightObject actor) {
        if (!actor.isPlayer()) {
            return false;
        }
        // 只能是pvp生效
        if (fight.getType() != Const.fightType_PK) {
            return false;
        }
        return FightRateUtil.isHit(50, 100);
    }
}
